package com.quantgroup.data.config;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.prometheus.client.Histogram;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yangjinhua
 */
@Configuration
public class MicrometerRegistry {

    @Autowired
    PrometheusMeterRegistry registry;

    @Bean
    MeterRegistryCustomizer<MeterRegistry> meterRegistryCustomizer(@Value("${spring.application.name}") String applicationName) {
        return registry -> registry.config().commonTags("application", applicationName);
    }



//    @Bean
//    Counter getRequestCounter() {
//        return Counter.build()
//                .name("io_http_requests_total")
//                .help("接口请求数")
//                .labelNames("clientName", "uri")
//                .help("Total requests.")
//                .register(registry.getPrometheusRegistry());
//    }


    @Bean
    Histogram getHistogram(){
        return Histogram.build().labelNames("uri", "accessType", "code")
                .name("api_cost_histogram").help("请求耗时histogram")
                .buckets(100,500,1000,3000).register(registry.getPrometheusRegistry());
    }

}
